#ifndef AVDEMUXER_H
#define AVDEMUXER_H
#include<atomic>
#include<QString>
#include<thread>
#include<memory>
#include<functional>

struct AVFormatContext;
class AVDeMuxer
{
public:
    AVDeMuxer();
    bool Open(const QString path);
    using StreamCallback = std::function<void(bool)>;
    inline void SetStreamCallback(const StreamCallback& cb){
        streamCb_ = cb;
    }
protected:
    void Close();
    void FetchStream(const QString path);
    bool FetchStreamInfo(const QString path);
    static int InterruptFountion(void* arg);
private:
    int videoIndex = -1;
    int AudioIndex = -1;
    std::atomic_bool quit_ ;
    AVFormatContext* pFormatCtx_ = nullptr;
    std::unique_ptr<std::thread> readThread_ = nullptr;
    StreamCallback streamCb_ = [](bool){};
};

#endif // AVDEMUXER_H
